package com.yuanlrc.base.controller.admin;

import com.yuanlrc.base.bean.CodeMsg;
import com.yuanlrc.base.bean.PageBean;
import com.yuanlrc.base.bean.Result;
import com.yuanlrc.base.entity.admin.Borrow;
import com.yuanlrc.base.entity.admin.Violation;
import com.yuanlrc.base.service.admin.OperaterLogService;
import com.yuanlrc.base.service.admin.ViolationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 违规的控制器
 */
@Controller
@RequestMapping("/violation")
public class ViolationController {
    private Logger log = LoggerFactory.getLogger(RoleController.class);
    @Autowired
    private ViolationService violationService;

    /**
     * 分页显示违规列表
     */
    @Autowired
    private OperaterLogService operaterLogService;
    @RequestMapping(value = "/list")
    public String borrowList(Model model, Violation violation, PageBean<Violation> pageBean){
        model.addAttribute("title","逾期列表");
        model.addAttribute("pageBean", violationService.findByName(violation, pageBean));
        return "/admin/borrow/violist";
    }

    /**
     * 删除记录
     * @param id
     * @return
     */
    @RequestMapping(value="delete",method= RequestMethod.POST)
    @ResponseBody
    public Result<Boolean>delete(@RequestParam(name = "id",required = true)Long id){
        try {
            violationService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(CodeMsg.VIOLATION_DELETE_ERROR);
        }
        log.info("删除记录ID【"+id+"】");
        return Result.success(true);
    }

}
